import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Lunbo from "../views/admin/Lunbo.vue";
Vue.use(VueRouter);

const routes = [
  {
    path: "/home",
    name: "Home",
    alias: "/",
    component: Home,
  },
  {
    path: "/admin",
    name: "Admin",
    redirect: (to) => {
      return { name: "Lunbo", query: { q: to.params.searchText } };
    },
    component: () => import("../views/Admin.vue"),
    children: [
      {
        path: "lunbo",
        name: "Lunbo",
        component: Lunbo,
      },
      {
        path: "article",
        name: "Article",
        component: () => import("../views/admin/Article.vue"),
      },
      {
        path: "create",
        name: "Create",
        component: () => import("../views/admin/Create.vue"),
      },
      {
        path: "detail/:article_id",
        name: "Detail",
        component: () => import("../views/admin/Detail.vue"),
      },
      {
        path: "modify/:article_id",
        name: "Modify",
        component: () => import("../views/admin/Modify.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
